    package com.qianji.petmall.product.app;

    import com.qianji.common.utils.PageUtils;
    import com.qianji.common.utils.R;
    import com.qianji.petmall.product.entity.SpuInfoEntity;
    import com.qianji.petmall.product.service.SpuInfoService;
    import com.qianji.petmall.product.vo.SpuSaveVo;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import java.util.Arrays;
    import java.util.Map;

    //import org.apache.shiro.authz.annotation.RequiresPermissions;



    /**
     * spu信息
     *
     * @author xiaoxin
     * @email 485350978@qq.com
     * @date 2022-01-07 14:35:43
     */
    @RestController
    @RequestMapping("product/spuinfo")
    public class SpuInfoController {
        @Autowired
        private SpuInfoService spuInfoService;

        /**
         * product/spuinfo/11/up
         */
        @PostMapping("{spuId}/up")
        public R getSkuInfoBySkuId(@PathVariable("spuId") Long spuId){
            spuInfoService.getSkuInfoBySkuId(spuId);
            return R.ok();
        }

        /**
         * 通过skuId查询spu的商品
         * @param skuId
         * @return
         */
        @PostMapping("skuId/{id}")
        public R getSkuInfoBySpuId(@PathVariable("id") Long skuId){
            SpuInfoEntity skuInfoBySpuId = spuInfoService.getSkuInfoBySpuId(skuId);
            return R.ok().setData(skuInfoBySpuId);
        }
        /**
         * 列表
         */
        @RequestMapping("/list")
        //@RequiresPermissions("product:spuinfo:list")
        public R list(@RequestParam Map<String, Object> params){
            PageUtils page = spuInfoService.queryPageByCondition(params);

            return R.ok().put("page", page);
        }


        /**
         * 信息
         */
        @RequestMapping("/info/{id}")
        //@RequiresPermissions("product:spuinfo:info")
        public R info(@PathVariable("id") Long id){
            SpuInfoEntity spuInfo = spuInfoService.getById(id);

            return R.ok().put("spuInfo", spuInfo);
        }

        /**
         * 保存
         */
        @RequestMapping("/save")
        //@RequiresPermissions("product:spuinfo:save")
        public R save(@RequestBody SpuSaveVo saveVo){
    //		spuInfoService.save(saveVo);
            spuInfoService.saveSpuInfo(saveVo);
            return R.ok();
        }

        /**
         * 修改
         */
        @RequestMapping("/update")
        //@RequiresPermissions("product:spuinfo:update")
        public R update(@RequestBody SpuInfoEntity spuInfo){
            spuInfoService.updateById(spuInfo);

            return R.ok();
        }

        /**
         * 删除
         */
        @RequestMapping("/delete")
        //@RequiresPermissions("product:spuinfo:delete")
        public R delete(@RequestBody Long[] ids){
            spuInfoService.removeByIds(Arrays.asList(ids));

            return R.ok();
        }

    }
